<?php
// +----------------------------------------------------------------------
// | Copyright (c) 2019~2022 https://www.meoyun.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件，不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 喵云科技 【https://www.meoyun.com】
// +----------------------------------------------------------------------


namespace app\common\service;

/**
 * 消息服务类
 */

use app\model\MessageModel;
use support\Db;
class Message
{

    public static function send($from_uid, $to_uid, $post_id, $type, $content = "", $title = "")
    {

        /**
         * type 消息类型：1=点赞,2=评论,3=收藏,4=关注,5=系统通知,6=公告
         */

        $data["from_uid"] = $from_uid;
        $data["to_uid"] = $to_uid;
        $data["post_id"] = $post_id;
        $data["title"] = $title;
        $data["content"] = $content;
        $data["type"] = $type;

        $where["from_uid"] = $from_uid;
        $where["to_uid"] = $to_uid;
        $where["type"] = $type;
        $where["post_id"] = $post_id;
        $where["content"] = $content;

        if ($from_uid != $to_uid) {
            $res = MessageModel::where($where)->first();
            if (!$res) {
                MessageModel::create($data);
            }
        }
    }
}